package com.ews.onlineexchange.controller;

import javax.enterprise.context.ConversationScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;

import com.ews.onlineexchange.dao.AgentServiceDao;
import com.ews.onlineexchange.model.AgentService;
import com.ews.onlineexchange.model.Article;
import com.ews.onlineexchange.model.ShortMessage;
import com.ews.onlineexchange.service.EntityHome;

@Named
@ConversationScoped
public class AgentServiceHome extends EntityHome<AgentService, String> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Inject
	AgentServiceDao agentServiceDao;
	
	@Override
	public String saveAndFlush() {
		boolean managed = isManaged();
		if(!managed) {//新增时判断
			if(agentServiceDao.findByName(getInstance().getName())) {
				FacesContext.getCurrentInstance().addMessage("agentServiceName",
						new FacesMessage(FacesMessage.SEVERITY_ERROR, "服务事项名称已存在！", ""));
				return null;
			}
		}
//		if(getInstance().getQualificationClass() == null) {
//			FacesContext.getCurrentInstance().addMessage("qualificationClass",
//					new FacesMessage(FacesMessage.SEVERITY_ERROR, "请选择资质大类！", ""));
//			return null;
//		}
		
		return super.saveAndFlush();
	}
//	@Inject
//	EntityManager entityManager;
//	public void deleteSms(String id) {
//		Article article = entityManager.find(Article.class, id);
//		article.setDelFlag("1");
//		entityManager.merge(article);
//	}
	
	
}
